package btanalyzer.db.report;

import java.math.BigInteger;
import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Component;

@Component("ReportPieceQuanity")
public class ReportPieceQuanity extends AbstractReport {

	@Override
	protected String reportOutptFileName() {
		return "ReportPieceQuanity.txt";
	}

	@Override
	protected void generateInt() {
		Query q = em.createNativeQuery("select m.piece_quantity from metadata m order by m.piece_quantity asc");
		Query q1 = em.createNativeQuery("select max(m.piece_quantity) from metadata m");
		@SuppressWarnings("unchecked")
		List<Integer> res = q.getResultList();
		int[] results = new int[((Integer)q1.getSingleResult()) + 1];
		for (int i = 0; i < results.length; i++) {
			results[i] = 0;
		}
		for (int i : res) {
			results[i]++;
		}
		
		// print results
		
		pw.println("Wszystkich wynikow:\t" + res.size());
		pw.println();
		pw.println("ilosc fragmentow\tilosc torrentow");
		for (int i = 0; i < results.length; i++) {
			long l = results[i];
			pw.println(i + "\t" + l);
		}
	}

}
